package cn.wolfcode.luowowo.flight.domain;

import cn.wolfcode.luowowo.common.domain.BaseDomain;
import cn.wolfcode.luowowo.common.util.DateUtil;
import cn.wolfcode.luowowo.flight.util.DateUtils;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class AirTicketDetail extends BaseDomain {

    public static final int AIR_SIZE_SMALL = 1;
    public static final int AIR_SIZE_MIDDLE = 2;
    public static final int AIR_SIZE_BIG = 3;

    //航空公司
    private Airlines airlines;

    //航次
    private String flight;

    //飞机类型
    private String airplaneType;

    //起飞地点
    private AirDest beginDest;

    //起飞时间
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date beginFlyTime;

    //起飞机场
    private Airport beginAirport;

    //起飞航站楼
    private String beginHZL;

    //目的地
    private AirDest endDept;

    //到达时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endFlyTime;

    //到达机场
    private Airport endAirport;

    //到达航站楼
    private String endHZL;

    //飞机大小
    private Integer size;

    //价格
    private BigDecimal price;


    public String getBetweenTime(){

        long dateBetween = DateUtil.getDateBetween(beginFlyTime, endFlyTime);
        long min = dateBetween%60==0 ? dateBetween/60 : dateBetween/60+1;
        return min/60 +"小时"+min%60+"分钟";

    }


    public String getInfo(){
        Map<String,Object> map = new HashMap<>();
        map.put("airlines",airlines);
        map.put("flight",flight);
        map.put("airplaneType",airplaneType);
        map.put("beginDest",beginDest);
        map.put("beginFlyTime",beginFlyTime);
        map.put("beginAirport",beginAirport);
        map.put("beginHZL",beginHZL);
        map.put("endDept",endDept);
        map.put("endFlyTime",endFlyTime);
        map.put("endAirport",endAirport);
        map.put("endHZL",endHZL);
        map.put("size",size);
        map.put("price",price);
        return JSON.toJSONString(map);
    }

    public String getWeek(){
      return   DateUtils.getWeek(beginFlyTime);
    }

    public String getCrossDay(){
        Calendar c = Calendar.getInstance();
        c.setTime(beginFlyTime);
        int depDay = c.get(Calendar.DAY_OF_YEAR);
        c.setTime(endFlyTime);
        int souDay = c.get(Calendar.DAY_OF_YEAR);
        return  depDay==souDay?null:"+1天";
    }

}